import PouchDB from 'pouchdb'

const db = new PouchDB('vr_show_list_home')

export function save(data = {}) {
  const { type, list } = data
  const putData = {
    _id: type,
    list,
    time: new Date().getTime()
  }
  return db.get(type)
    .then(doc => {
      putData['_rev'] = doc._rev
      return db.put(putData)
    })
    .catch(() => {
      return db.put(putData)
    })
}

export function read(type) {
  return db.get(type)
}
